<?php
class ArticleModel extends Model {
	// 自动验证设置
	protected $_validate = array(
		array('ar_title', 'require', '请填写标题！'),
		array("ar_content", 'require', '请填写留言内容！'),
	);

	/**
     * 获取上一条记录
     * @param   int    $id   文章ID
     * @return  int          上一条ID
     */
	public static function lastSectionRecord($id)
	{
		if (empty($id))
		{
			return null;
		}

        $lastId = M("article")->field("ar_id")->where("ar_id < " . $id)->order("ar_id desc")->limit(1)->find();
	    
	    if (!empty($lastId['ar_id'])) {
	    	return $lastId['ar_id'];
	    }

	    return null; 
	}

	/**
     * 获取下一条记录
     * @param   int    $id   文章ID
     * @return  int          下一条ID
     */
	public static function nextSectionRecord($id)
	{
		if (empty($id))
		{
			return null;
		}

        $nextId = M("article")->field("ar_id")->where("ar_id > " . $id)->order("ar_id asc")->limit(1)->find();
	    
	    if (!empty($nextId['ar_id'])) {
	    	return $nextId['ar_id'];
	    }

	    return null; 
	}
}
?>